package com.zhangdi.mserver.searchcli.repository;

import com.zhangdi.mserver.searchcli.HighlightResponse;
import com.zhangdi.mserver.searchcli.MFunctionScore;
import com.zhangdi.mserver.searchcli.MSearchRequest;
import com.zhangdi.mserver.searchcli.page.Page;
import com.zhangdi.mserver.searchcli.page.Pageable;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;

import java.util.List;
import java.util.Map;

public interface ClientApi<T> {
    List<T> search(MSearchRequest c, Class<T> tClass, String indexName, String[] includeField, String[] excludeField);
    Page<T> search(Pageable<List<MSearchRequest>> pageable, Class<T> tClass, String indexName,
                   String[] includeField,
                   String[] excludeField);
    Page<T> search(MFunctionScore option, Class<T> tClass, String[] includeField, String[] excludeField);

    List<T> search(MSearchRequest c, Class<T> tClass, String indexName);
    List<T> search(List<MSearchRequest> pageable, Class<T> tClass);
    Page<T> search(Pageable<List<MSearchRequest>> pageable, Class<T> tClass, String indexName);
    Map<String, Object> search(Pageable<List<MSearchRequest>> pageable);
    HighlightResponse highlightSearch(Pageable<List<MSearchRequest>> pageable, HighlightBuilder highlightBuilder,
                                      String[] includeField, String indexName);

    /**
     * should
     * @param pageable
     * @param shoulds
     * @param tClass
     * @param indexName
     * @return
     */
    Page<T> search(Pageable<List<MSearchRequest>> pageable, List<MSearchRequest> shoulds, Class<T> tClass,
                   String indexName,
                   String[] includeField,
                   String[] excludeField);

    Page<T> search(MFunctionScore option, Class<T> tClass);

    Page<T> searchShouldByGroup(Pageable<List<MSearchRequest>> pageable, List<List<MSearchRequest>> shoulds, Class<T> tClass,
                   String indexName,
                   String[] includeField,
                   String[] excludeField);

    Page<T> searchByNestedGroup(Pageable<List<MSearchRequest>> pageable, List<List<MSearchRequest>> nestedMustGroup, List<List<MSearchRequest>> shoulds,
                                       Class<T> tClass, String indexName, String[] includeField, String[] excludeField);

    BulkResponse bulk(BulkRequest bulkRequest, RequestOptions options);
}
